package com.zrx.controller;

import com.zrx.constants.SystemConstants;
import com.zrx.domain.ResponseResult;
import com.zrx.domain.dto.AddCommentDto;
import com.zrx.domain.entity.Comment;
import com.zrx.service.CommentService;
import com.zrx.utils.BeanCopyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 张荣欣
 * @create ：2022/9/19  14:32
 */
@RestController
@RequestMapping("/comment")
@Api(tags = "用户评论")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @GetMapping("/commentList")
    @ApiOperation(value = "文章评论列表查询",notes = "文章评论列表查询")
    public ResponseResult commentList(Integer pageNum,Integer pageSize,Long articleId){
        return commentService.commentList(SystemConstants.ARTICLE_COMMENTS,articleId,pageNum,pageSize);
    }

    @PostMapping
    @ApiOperation(value = "文章评论添加",notes = "文章评论添加")
    private ResponseResult addComment(@RequestBody AddCommentDto addCommentDto){
        Comment comment = BeanCopyUtils.copyBean(addCommentDto, Comment.class);
        return commentService.addComment(comment);
    }

    @GetMapping("/linkCommentList")
    @ApiOperation(value = "友链评论列表查询",notes = "友链评论列表查询")
    public ResponseResult linkCommentList(Integer pageNum,Integer pageSize){
        return commentService.commentList(SystemConstants.LINK_STATUS_COMMENTS,null,pageNum,pageSize);
    }
}
